import Vue from 'vue'
import Router from 'vue-router'
import utils from '../utils'
import api from '../api'

Vue.use(Router)
const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/', // 首页默认 信贷客
      component: resolve => {
        require(['../pages/CreditLoan'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 注册
    {
      path: '/passport/register',
      component: resolve => {
        require(['../pages/Register'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 对应旧信贷动力路由
    {
      path: '/active/invite/register',
      component: resolve => {
        require(['../pages/Register'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 登录
    // 手机验证
    {
      path: '/passport/login',
      component: resolve => {
        require(['../pages/Login'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 用户登录
    {
      path: '/customer/apply',
      component: resolve => {
        require(['../pages/UserLogin'], resolve)
      }
    },
    {
      path: '/customer/verify',
      component: resolve => {
        require(['../pages/UserLogin'], resolve)
      }
    },
    // 用户表单
    {
      path: '/customer/complete',
      component: resolve => {
        require(['../login/UserForm'], resolve)
      }
    },
    {
      path: '/login',
      component: resolve => {
        require(['../pages/Login'], resolve)
      }
    },
    // 忘记密码
    {
      path: '/passport/forgetPassword',
      component: resolve => {
        require(['../login/ForgetPassword'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 设置新密码
    {
      path: '/passport/updatePassword',
      component: resolve => {
        require(['../login/SetPassword'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 信贷客
    {
      path: '/creditGuest/index',
      component: resolve => {
        require(['../pages/CreditLoan'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 信贷客着陆页
    {
      path: '/creditLogin/index',
      component: resolve => {
        require(['../components/CreditLogin'], resolve)
      }
    },
    // 信贷客详情页 信贷
    {
      path: '/loanGuest/detail',
      component: resolve => {
        require(['../components/LoanDetail'], resolve)
      }
    },
    // 信贷客详情页 信用卡
    {
      path: '/creditGuest/detail',
      component: resolve => {
        require(['../components/CreditDetail'], resolve)
      }
    },
    // 内容推广
    {
      path: '/article/index',
      component: resolve => {
        require(['../pages/ContentPromote'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 图片推广
    {
      path: '/picture/index',
      component: resolve => {
        require(['../pages/ImgtextPromote'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 二维码推广
    {
      path: '/qrcode/index',
      component: resolve => {
        require(['../pages/CodePromote'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 信贷客申请页
    {
      path: '/creditloan/creditlogin',
      component: resolve => {
        require(['../components/CreditLogin'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 文章详情
    {
      path: '/article/detail',
      component: resolve => {
        require(['../components/ContentDetail'], resolve)
      }
    },
    // 分享后文章详情
    {
      path: '/article/detail_out',
      component: resolve => {
        require(['../components/SharecontentDeatil'], resolve)
      }
    },
    // 选择模板
    {
      path: '/picture/template',
      component: resolve => {
        require(['../components/TemplateBank'], resolve)
      }
    },
    // 历史图片
    {
      path: '/center/collect',
      component: resolve => {
        require(['../components/HistoryTemplate'], resolve)
      }
    },
    // 添加宣传语
    {
      path: '/picture/slogan',
      component: resolve => {
        require(['../components/AddTagline'], resolve)
      }
    },
    // 分享后 图片详情
    {
      path: '/picture/detail',
      component: resolve => {
        require(['../components/ImgDetail'], resolve)
      }
    },
    // 交易大厅
    {
      path: '/fly/index',
      component: resolve => {
        require(['../pages/FleaMarket'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 代理中心
    // 个人中心
    {
      path: '/center/index',
      component: resolve => {
        require(['../pages/PersonCenter'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 个人信息
    {
      path: '/center/setting',
      component: resolve => {
        require(['../agencycenter/personmessage/PersonMessage'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 修改姓名
    {
      path: '/setting/name',
      component: resolve => {
        require(['../agencycenter/personmessage/ChangeName'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 修改手机号
    {
      path: '/setting/mobile',
      component: resolve => {
        require(['../agencycenter/personmessage/ChangeMobile'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 新手机号
    {
      path: '/mobile/change',
      component: resolve => {
        require(['../agencycenter/personmessage/MobileNext'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 绑卡
    {
      path: '/setting/card',
      component: resolve => {
        require(['../comment/ChangeCredit'], resolve)
      }
    },
    // 我要提现
    {
      path: '/center/withdraw',
      component: resolve => {
        require(['../agencycenter/mycredit/MyCredit'], resolve)
      },
      meta: {
        requireAuth: true,
        requireLogin: true
      }
    },
    // 提现记录
    {
      path: '/center/record',
      component: resolve => {
        require(['../agencycenter/mycredit/Record'], resolve)
      }
    },
    // 可提现余额
    {
      path: '/center/balance',
      component: resolve => {
        require(['../agencycenter/mycredit/Balance'], resolve)
      }
    },
    // 收支明细
    {
      path: '/center/balancepayment',
      component: resolve => {
        require(['../agencycenter/BalancePayment'], resolve)
      }
    },
    // 收益明细
    {
      path: '/center/incomeDetail',
      component: resolve => {
        require(['../agencycenter/MyEarnings'], resolve)
      }
    },
    // 客户列表
    {
      path: '/center/customer',
      component: resolve => {
        require(['../agencycenter/ClientList'], resolve)
      }
    },
    // 公告
    {
      path: '/center/notice',
      component: resolve => {
        require(['../agencycenter/notice/Notice'], resolve)
      }
    },
    // 公告详情
    {
      path: '/notice/detail',
      component: resolve => {
        require(['../agencycenter/notice/NoticeDetail'], resolve)
      }
    },
    // 新手指南
    {
      path: '/center/guide',
      component: resolve => {
        require(['../agencycenter/NewFingerpost'], resolve)
      }
    },
    // 轻松一刻
    {
      path: '/center/easy',
      component: resolve => {
        require(['../agencycenter/EasyTime'], resolve)
      }
    },
    // 奖励说明
    {
      path: '/center/award',
      component: resolve => {
        require(['../agencycenter/AwardState'], resolve)
      }
    },
    // 关于我们
    {
      path: '/center/aboutus',
      component: resolve => {
        require(['../agencycenter/AboutUs'], resolve)
      }
    },
    // 咨询
    {
      path: '/center/consult',
      component: resolve => {
        require(['../agencycenter/consult/Consult'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 新问题
    {
      path: '/consult/question',
      component: resolve => {
        require(['../agencycenter/consult/NewQuestion'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 邀请好友
    {
      path: '/center/invitation',
      component: resolve => {
        require(['../pages/InviteFriends'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 团队收益
    {
      path: '/center/team',
      component: resolve => {
        require(['../agencycenter/invite/TeamEarnings'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 信贷圈子
    {
      path: '/circle/index',
      component: resolve => {
        require(['../pages/CreditCircle'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 发布
    {
      path: '/circle/myissue',
      component: resolve => {
        require(['../agencycenter/creditcircle/MyIssue'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 信贷圈子-内容详情
    {
      path: '/circle/detail',
      component: resolve => {
        require(['../agencycenter/creditcircle/CreditDetail'], resolve)
      }
    },
    // 信贷圈子-回复
    {
      path: '/circle/reply',
      component: resolve => {
        require(['../agencycenter/creditcircle/ContentReply'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // 信贷圈子协议
    {
      path: '/circle/protocol',
      component: resolve => {
        require(['../agencycenter/creditcircle/CircleProtocol'], resolve)
      }
    },
    // 邀请跳转到个人中心中间层
    {
      path: '/middleBack',
      component: resolve => {
        require(['../pages/MiddleBack'], resolve)
      }
    },
    // 工具箱
    {
      path: '/toolBox/index',
      component: resolve => {
        require(['../pages/ToolBox'], resolve)
      }
    },
    {
      path: '/tool/carloan',
      component: resolve => {
        require(['../toobox/CarLoan'], resolve)
      }
    },
    {
      path: '/tool/houseloan',
      component: resolve => {
        require(['../toobox/HouseLoan'], resolve)
      }
    },
    {
      path: '/tool/financecount',
      component: resolve => {
        require(['../toobox/FinanceCount'], resolve)
      }
    },
    {
      path: '/tool/personcount',
      component: resolve => {
        require(['../toobox/PersonCount'], resolve)
      },
      meta: {
        requireAuth: true
      }
    },
    // APP下载
    {
      path: '/load/index',
      component: resolve => {
        require(['../pages/DownLoad'], resolve)
      },
      meta: {
        requireAuth: true
      }
    }
  ]
})
// const location = global.location

/* router.beforeEach((to, from, next) => {
  console.log(location.href)
  console.log(to)
  if (utils.isIOS() && utils.isWeixin()) {
    // location.assign(to.fullPath)
    var lastParams = localStorage.getItem('lastParam')
    var currentParams = location.search
    if (lastParams === 'undefined' || lastParams === undefined) {
      location.replace(to.fullPath)
    }
    if (lastParams !== 'undefined' && currentParams !== lastParams) {
      location.serach = lastParams
    }
  } else {
    next()
  }
}) */

/* var status = localStorage.getItem('status')@
  console.log(status)
  next()
  if (to.matched.some(r => r.meta.requireAuth) && status !== 'loggedin') {
    next({
      query: {
        redirect: to.fullPath
      }
    })
  } else {
    next()
  } */
import store from '../store/store'

router.afterEach((to, from) => {
  console.log(to)
  console.log(from)
  if (utils.isAndroid() && to.fullPath !== from.fullPath) {
    console.log('re jssdk in andro')
    utils.jssdkwx(api, Vue.wechat, store, null)
  }
})

export default router
